﻿using AutoMapper;
using NetTaste;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using VM.Common.Result;
using VM.Entity.EntityMap.ICon;
using VM.Entity.EntityMap.Member;
using VM.Entity.EntityMap.Menu;
using VM.Entity.EntityMap.System.Code;
using VM.Entity.EntityMap.Topic;
using VM.IDAL.ICon;

namespace VM.DAL.ICon
{
    public class IConDAL : BaseDAL, IIconDAL
    {

        protected ISqlSugarClient _Client { get; set; }
        protected IMapper _IMapper { get; set; }

        public IConDAL(ISqlSugarClient client, IMapper iMapper) : base(client)
        {
            _Client = client;
            _IMapper = iMapper;
        }

        public PagingData<sys_icon> getIconList(string? name, int userId, int pageSize, int pageIndex)
        {
            var ListRes = _Client.Queryable<sys_icon>()
                         .Includes(a => a.createUser)
                         .Includes(a => a.updateUser)
                         .WhereIF(name != null && name != "", a => a.pcName.Contains(name) || a.appName.Contains(name))
                         .OrderBy(a => a.id);

            PagingData<sys_icon> result = new PagingData<sys_icon>()
            {
                dataList = ListRes.ToPageList(pageIndex, pageSize),
                pageIndex = pageIndex,
                pageSize = pageSize,
                recordCount = ListRes.Count(),
                searchString = name
            };

            return result;




        }

        public int addIcon(sys_icon obj)
        {
            int Res = _Client.Insertable(obj).ExecuteCommand();
            return Res;
        }
    }
}
